﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NetfractionHub.Network.Protocol;
using NetfractionHub.Network.Protocol.BASE.Factory;
using NetfractionHub.Network.Protocol.UCMD;
using NetfractionHub.Network.Protocol.UCMD.Factory;

namespace NetfractionHub.LocalMachine.BotCommands.Handler
{
    [CommandHandler("messageoftheday", TriggerAlias="motd")]
    [UserCommand("Show Message of the Day", FactoryCMD.ConextTypesEnum.HubCommand, "HMSG {0}motd\n")]
    [UserCommand("Set Message of the Day", FactoryCMD.ConextTypesEnum.HubCommand, "HMSG {0}motd\\\\s\"%[line:New Message of the Day]\"\n")]
    public class MessageOfTheDay : CommandHandler
    {
        public override BotReturnStatus HandleCommandMessage(NetfractionHub.RemoteMachine.Node source, CommandMessage message)
        {
            if (message.UnnamedArguments.Count == 0)
            {
                if (!Security.Permission.HasPermission(source.SecurityIdentity, typeof(Security.Permissions.GetMessageOfTheDayPermission)))
                    return new BotReturnStatus(false, Security.Permission.GetDeniedString(typeof(Security.Permissions.GetMessageOfTheDayPermission)));

                return new BotReturnStatus(true, string.Format("Message of the day: {0}", Settings.HubSettings.HubIdentity.MessageOfTheDay));
            }
            else if (message.UnnamedArguments.Count == 1)
            {
                if (!Security.Permission.HasPermission(source.SecurityIdentity, typeof(Security.Permissions.SetMessageOfTheDayPermission)))
                    return new BotReturnStatus(false, Security.Permission.GetDeniedString(typeof(Security.Permissions.SetMessageOfTheDayPermission)));

                Settings.HubSettings.HubIdentity.MessageOfTheDay = message.UnnamedArguments[0];
                return new BotReturnStatus(true, string.Format("{0} has set the hub topic to: {1}", source.Identity.Nickname, message.UnnamedArguments[0]), true);
            }
            else
                return false;
        }
    }
}
